package com.example.springtransdemo.demos.web.controller;

import com.example.springtransdemo.demos.web.service.LogService;
import com.example.springtransdemo.demos.web.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author Q
 * @create 2025-06-17-17:13
 */
@RequestMapping("/trans2")
@RestController
@Slf4j
public class Trans2Controller {
    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;


    @Transactional
    @RequestMapping("/r1")
    public Boolean registry(String name, String password){
        Integer result = userService.insertUser(name, password);
        log.info("用户表数据影响行数: "+ result);

        Integer logCount = logService.insertLog(name, "registry");
        log.info("日志表数据影响行数: "+ logCount);

        return true;
    }
}
